using System;
using System.Collections.Generic;
using System.Text;

namespace MIS.EN.Exchange.Entities
{
    /// <summary>
    /// Represents an item in the Exchange Store.
    /// </summary>
    public abstract class Item
    {
        private string id;
        private string href;
        private bool loadedFromServer;
        private bool doneLoadingFromServer;
        private List<string> propertiesChanged;
        
        /// <summary>
        /// Default constructor.
        /// </summary>
        protected Item() 
            : this(false)
        {
        }

        /// <summary>
        /// Overloaded constructor.
        /// </summary>
        /// <param name="loadedFromServer">Indicates if the item has been loaded from the server or created as a new instance.</param>
        protected Item(bool loadedFromServer)
        {
            this.id = string.Empty;
            this.href = string.Empty;
            this.loadedFromServer = loadedFromServer;
            this.propertiesChanged = new List<string>();
        }

        /// <summary>
        /// The name of the item as it is saved in the Exchange store.
        /// </summary>
        public abstract string Name
        {
            get;
        }

        /// <summary>
        /// Specifies the globally unique identifier (GUID) of an item. This field is read-only.  Maps to the DAV:id field.
        /// </summary>
        public string Id
        {
            get { return this.id; }
            internal set { this.id = value; }
        }

        /// <summary>
        /// The absolute URL of an item.  Maps to the DAV:href field.
        /// </summary>
        public string Href
        {
            get { return this.href; }
            set { this.href = value; }
        }

        /// <summary>
        /// Indicates if the item has been loaded from the server or created as a new instance.
        /// </summary>
        protected bool LoadedFromServer
        {
            get { return this.loadedFromServer; }
        }

        /// <summary>
        /// True indicates that the item is done being loaded from the server.
        /// </summary>
        internal bool DoneLoadingFromServer
        {
            get { return this.doneLoadingFromServer; }
            set { this.doneLoadingFromServer = value; }
        }

        /// <summary>
        /// The list of property names whose associated property values have been set.
        /// </summary>
        internal IList<string> PropertiesChanged
        {
            get { return this.propertiesChanged; }
        }

        /// <summary>
        /// Adds a property name to the internal list of properties that have been set.
        /// </summary>
        /// <param name="propertyName">The name of the property that was set.</param>
        protected void AddPropertyChanged(string propertyName)
        {
            if (!this.propertiesChanged.Contains(propertyName))
            {
                this.propertiesChanged.Add(propertyName);
            }
        }
    }
}
